#include "GSCharacterCreation.h"
#include "GSMainMenu.h"
#include "GSWeekday.h"

GSCharacterCreation::GSCharacterCreation()
{
	SetStateName("GSCHARACTERCREATION");
}

GSCharacterCreation::~GSCharacterCreation()
{

}

void GSCharacterCreation::OnEnter()
{
	fontCustom = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/mv_boli.png");
	fontCustomBig = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/Showcard_Gothic.png");
	nameBox = DEVICE->GetGUI()->addEditBox(L"", core::rect<s32>(SCREEN_WIDTH/2, SCREEN_HEIGHT/2,100,20));
	nameBox->setMax(45);
	nameBox->setRelativePosition(irr::core::recti(0,0,200,20));
	nameBox->setRelativePosition(irr::core::position2di(NAME_BOX_X - 100,NAME_BOX_Y));
	nameBox->setOverrideFont(fontCustom);
	pName = "";
	state = CNAME;
	mainAttrib = -1;
	isNameEmpty = false;
}

void GSCharacterCreation::OnExit()
{

}

void GSCharacterCreation::Update()
{
	switch(state)
	{
	case CNAME:
		{
			DEVICE->GetGUI()->setFocus(nameBox);
			if(DEVICE->receiver.IsKeyUp(KEY_RETURN))
			{
				pName = nameBox->getText();
				if(pName == L"")
					isNameEmpty = true;
				else
					state = CCLASS;
			}
			if(DEVICE->receiver.IsKeyUp(KEY_KEY_2))
				Game::SetState((GameState*)new GSMainMenu());
			break;
		}
	case CCLASS:
		{
			if(Game::GetDevice()->receiver.IsKeyUp(KEY_KEY_1))
			{
				mainAttrib = ATTRIB_MATH;
			}
			else if(Game::GetDevice()->receiver.IsKeyUp(KEY_KEY_2))
			{
				mainAttrib = ATTRIB_SCIENCE;
			}
			else if(Game::GetDevice()->receiver.IsKeyUp(KEY_KEY_3))
			{
				mainAttrib = ATTRIB_PE;
			}
			if(mainAttrib >= 0)
			{
				Game::GetInstance()->CreatePlayer(pName, mainAttrib, RANK_F);
				Game::SetState((GameState*)new GSWeekday());
			}
			break;
		}
	}
}

void GSCharacterCreation::Render()
{
	Game::GetDevice()->GetDriver()->beginScene(true, true, video::SColor(255,255,255,255));
	switch(state)
	{
	case CNAME:
		{
			if(isNameEmpty)
				fontCustom->draw("Please Enter a Name!", core::rect<s32>(SCREEN_WIDTH/2 - 100, 150,100,50), video::SColor(255,255,0,0));
			fontCustomBig->draw("Enter Name", core::rect<s32>(SCREEN_WIDTH/2 - 100, 200,100,50), video::SColor(255,0,0,0));
			nameBox->draw();
			break;
		}
	case CCLASS:
		{
			fontCustomBig->draw("Select your Major Subject", core::rect<s32>(SCREEN_WIDTH/2 - 100, 200,100,50), video::SColor(255,0,0,0));
			fontCustom->draw("1. Math", core::rect<s32>(SCREEN_WIDTH/2 - 100, SCREEN_HEIGHT/2,100,50), video::SColor(255,0,0,0));
			fontCustom->draw("2. Science", core::rect<s32>(SCREEN_WIDTH/2 - 100, SCREEN_HEIGHT/2 + 50,100,50), video::SColor(255,0,0,0));
			fontCustom->draw("3. PE", core::rect<s32>(SCREEN_WIDTH/2 - 100, SCREEN_HEIGHT/2 + 100,100,50), video::SColor(255,0,0,0));
			break;
		}
	}
	Game::GetDevice()->GetDriver()->endScene();
}